package br.com.marcelo.reservasis.domain.facade;

import br.com.aroeirasoftware.gwtcomponents.client.query.ASQuery;
import br.com.aroeirasoftware.gwtcomponents.client.query.ASQueryResult;
import br.com.aroeirasoftware.gwtcomponents.domain.facades.ASGWTFacade;
import br.com.aroeirasoftware.gwtcomponents.domain.facades.FacadeException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import net.sf.gilead.core.PersistentBeanManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Marcelo
 */
@Component("reservaEstadiaFacade")
@Transactional(propagation = Propagation.REQUIRES_NEW)
public class ReservaEstadiaFacade<E, PK extends Serializable> extends ASGWTFacade<E, PK> {

    @Autowired
    private PersistentBeanManager beanManager;

    @Override
    public ASQueryResult<E> getPorConsulta(ASQuery arg0) throws FacadeException {
        ASQueryResult<E> queryResult = super.getPorConsulta(arg0);
        List<E> listaConvertida = new ArrayList<E>();

        for (E e : queryResult.getLista()) {
            listaConvertida.add((E) beanManager.clone(e));
        }

        return new ASQueryResult<E>(queryResult.getPagina(), queryResult.getPaginas(), listaConvertida);
    }

    @Override
    public E getPorId(PK arg0) throws FacadeException {
        E arg0C = (E) beanManager.clone(super.getPorId(arg0));
        return arg0C;
    }
}
